<template>
	<div class="">
		<header class="top_bar">
			<a onclick="window.history.go(-1)" class="icon_back"></a>
			<h3 class="cartname">管理地址</h3>
			<a href="javascript:void(0)" class="icon_menu"></a>
		</header>
		<section class="padding_top45">
			<div v-for="item in addressList" class="margin_bot10 padding_lf6_rg6 background_fff">
				<div class="border_bot_dcdcdc padding_top10_bot10">
					<div class="font_size16 line_height1_5">
						<span>{{item.ReceiverName}}</span>
						<span>{{item.ReceiverPhone}}</span>
					</div>
					<div class="color666">
						{{item.AddrProvince}}{{item.AddrCity}}{{item.AddrArea}}{{item.AddrDetail}}
					</div>
				</div>
				<div class="overflow_hidden color666 line_height40">
					<div @click="setDefaultAdr(item.Id, item)" class="fl">
						<img v-if="item.Checked==1" class="vertical_align_mid" src="../assets/images/selected_icon1.png" />
						<img v-else class="vertical_align_mid" src="../assets/images/selected_icon0.png" />
						<span>设为默认</span>
					</div>
					<div @click="deleteAddressBtn(item)" class="fr">
						<img class="vertical_align_mid" src="../assets/images/delete_icon.png" />
						<span>删除</span>
					</div>
					<div @click="editAddressBtn(item)" class="fr margin_right10">
						<img class="vertical_align_mid" src="../assets/images/edit_icon.png" />
						<span>编辑</span>
					</div>
				</div>
			</div>
		</section>
		<router-link to="/AddressAdd">
			<div class="btn_bot">
				新建地址
			</div>
		</router-link>
	</div>
</template>
<script>
	import { Toast } from 'mint-ui';
	import { MessageBox } from 'mint-ui';
	export default {
		data() {
			return {
				addressList: [],
				popupVisibleAddAdr: false,
			}
		},
		mounted() {
			this.getUDatas();
		},
		methods: {
			getUDatas() {
				let _this = this;
				_this.$http.get('/client/Address', null, localStorage.Authorization, res => {
					console.log('地址列表res', res)
					if(res.code === 200) {
						_this.addressList = res.data.list;
					}else if(res.code === 101) {
						localStorage.fromPath = _this.$route.fullPath
						_this.$router.push({
							path: '/login'
						})
					}
				})
			},
			editAddressBtn(item) {
				let _this = this
				_this.$router.push({
					path: '/addressEdit',
					query: {
						item: item
					},
				})
			},
			deleteAddressBtn(item) {
				let _this = this;
				MessageBox.confirm('确定删除该地址？').then(action => {
					_this.$http.delete('/client/Address/' + item.Id, null, localStorage.Authorization, res => {
						console.log('删除地址getres', res)
						if(res.code === 200) {
							Toast(res.data);
							setTimeout(function() {
								_this.$router.go(0)
							}, 1000)
						}
					})
				}).catch(action => {
				})
			},
			setDefaultAdr(AddressId, item) {
				let _this = this;
				for(var i=0; i<_this.addressList.length; i++) {
					_this.addressList[i].Checked = 0
				}
				item.Checked = 1
				_this.$http.put('/client/Members/0', {
					AddressId: AddressId
				}, localStorage.Authorization, res => {
					console.log('设置默认地址res', res)
					if(res.code === 200) {
						Toast(res.data);
//						_this.$router.go(0)
					}
				})
			}
		}
	}
</script>
<style scoped="scoped">
	.btn_bot {
		position: fixed!important;
	}
	.footer{
		display: none;
	}
	/*.bottom66{
		bottom: 66px!important;
	}*/
</style>